/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.security.service.impl;

import com.google.common.collect.Maps;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.vacoor.nothing.web.domain.filter.GFR;
import org.vacoor.nothing.web.domain.filter.Rule;
import org.vacoor.nothing.web.service.support.CrudServiceImpl;

import org.vacoor.nothing.security.entity.User;
import org.vacoor.nothing.security.service.IUserService;

import java.util.List;
import java.util.Map;

/**
 * Created on 2015-01-15 14:34:02
 *
 * @author crud generated
 */
@Service
@Transactional
public class IUserServiceImpl extends CrudServiceImpl<User, String> implements IUserService {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        IUserService service = ctx.getBean(IUserService.class);
        Map<String, Object> paramsMap = Maps.newHashMap();
        GFR and = GFR.conjunction();
        and.addRule(Rule.eq("id", "123"))
            .addRule(Rule.isNull("locked_time"))
            .addGroupedFilter(GFR.disjunction().addRule(Rule.ne("username", "not")).addRule(Rule.eq("username", "ok")));
        GFR or = GFR.disjunction();
        or.addRule(Rule.eq("", ""));



        // (a.b.c = 123  and a.b = 123 and (a.b = 1 or a.id = 1 or a.b = 45)
        // a.b.c = (123)

        and.addGroupedFilter(or);

        paramsMap.put("_grouped_filter", and);
        List<User> many = service.findMany(paramsMap);
        System.out.println(many);
        System.out.println(service);
    }

}
